angular.module('session', [])

.config(function SessionRoute($stateProvider) {
    $stateProvider

    .state('session', {
        abstract: true,
        template: '<main ui-view></main>'
    })

    .state('session.signin', {
        url: '/signin?{referer:string}',
        params: { value: '%2F', squash: true },
        templateUrl: 'admin/session/signin.html',
        controller: 'SigninController as vm'
    })
        .state('session.register', {
            url: '/register',
            templateUrl: 'admin/session/register.html',
            controller: 'RegisterController as vm'
        })
        .state('session.success',{
            url: '/success',
            templateUrl: 'admin/session/success.html',
            controller:'SuccessController as vm'
        })
})
    .config(function cloudRoute($stateProvider) {
        $stateProvider

            .state('cloud', {
                parent: 'title',
                url: '/cloud',
                params: {
                    page: {value: 1, squash: true},
                    size: {value: 10, squash: true}
                },

                templateUrl: 'admin/eventCloud/eventCloud.html',
                controller: 'CloudController as vm',
                resolve: {}

            })

    })

    .controller('SigninController', SigninController)
    .controller('RegisterController', RegisterController)
    .controller('SuccessController', function SuccessController($state,$scope){
        var vm=this;
        vm.sec=5
        var updateClock=function(){
            if(vm.sec==0){
                clearInterval(vm.timer1)
                $state.go('session.signin')
                return
            }
            vm.sec--;
        }
        vm.timer1=setInterval(function () {
            $scope.$apply(updateClock());
        }, 1000);
    })
    .service('Register',RegisterModel)
